package cn.edu.jxyy.batistest.test;

import cn.edu.jxyy.batistest.mapper.CustomerMapper;
import cn.edu.jxyy.batistest.mapper.StudentMapper;
import cn.edu.jxyy.batistest.pojo.Customer;
import cn.edu.jxyy.batistest.pojo.Student;
import cn.edu.jxyy.batistest.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
//向学生t_student，使用<set>更新数据
public class Part15_Student {
    public static void  updateStudentBySet(){
        SqlSession sqlSession = MyBatisUtils.getSession();

        Student student = new Student();
        student.setId(1);
        student.setAge(28);

        StudentMapper studentMapper =
                sqlSession.getMapper(StudentMapper.class);

        int rows = studentMapper.updateStudentBySet(student);
        // 通过返回结果判断更新操作是否执行成功
        if (rows > 0) {
            System.out.println("您成功修改了" + rows + "条数据！");
        } else {
            System.out.println("执行修改操作失败！！！");
        }

        // 提交事务
        sqlSession.commit();
        // 关闭SqlSession
        sqlSession.close();
    }
    public static  void  updateStudentByTrim(){
        // 获取SqlSession
        SqlSession sqlSession = MyBatisUtils.getSession();
        // 创建Customer对象，并向对象中添加数据
        Student student = new Student();
        student.setId(1);
        student.setAge(28);
        // 执行SqlSession的更新方法，返回的是SQL语句影响的行数
        StudentMapper studentMapper =
                sqlSession.getMapper(StudentMapper.class);

        int rows = studentMapper.updateStudentByTrim(student);
        // 通过返回结果判断更新操作是否执行成功
        if (rows > 0) {
            System.out.println("您成功修改了" + rows + "条数据！");
        } else {
            System.out.println("执行修改操作失败！！！");
        }
        // 提交事务
        sqlSession.commit();
        // 关闭SqlSession
        sqlSession.close();
    }
    public static void main(String[] args){
        updateStudentBySet();
        updateStudentByTrim();
    }
}